import 'package:flutter/material.dart';
import '../../pages/shipuse/shipuse_authorty.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/inputWidget.dart';
import '../../model/station.dart';
import '../../model/shipuse.dart';
import '../../helper/Helper.dart';
import '../../helper/global_config.dart';
import '../../helper/uidata.dart';
import '../../model/report.dart';

class ShipUseHuiZhiAddPage extends StatefulWidget {
  @override
  ShipUseHuiZhiAddPage(this.s1, this.added);
  final ShipUse s1;
  final VoidCallback added;
  @override
  ShipUseHuiZhiAddPageState createState() => new ShipUseHuiZhiAddPageState();
}

class ShipUseHuiZhiAddPageState extends State<ShipUseHuiZhiAddPage> {
  late ShipUse X1;

  final TextEditingController c1 = new TextEditingController();
  final TextEditingController c2 = new TextEditingController();
  final TextEditingController c3 = new TextEditingController();
  final TextEditingController c4 = new TextEditingController();
  final TextEditingController c5 = new TextEditingController();
  final TextEditingController c6 = new TextEditingController();
  final TextEditingController c7 = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    X1 = widget.s1;

    c1.text = X1.ManaName;
    c2.text = X1.CZName;
    c3.text = X1.ChuanBo;
    c4.text = X1.CunDang;
    c5.text = X1.TianQi;
    c6.text = X1.HangXing;
    c7.text = X1.ManaPhone;

    if (c1.text.length < 2) c1.text = UIData.CurrentUser!.Name;

    if (c4.text.length < 2) c4.text = UIData.CurrentUser!.Name;

    if (c7.text.length < 2) c7.text = UIData.CurrentUser!.Phone;
  }

  upload(BuildContext context) async {
    if (X1.State < 4) {
      return;
    }

    X1.ManaName = c1.text;
    X1.CZName = c2.text;
    X1.ChuanBo = c3.text;
    X1.CunDang = c4.text;
    X1.TianQi = c5.text;
    X1.HangXing = c6.text;
    X1.ManaPhone = c7.text;
    X1.CZPhone = "  ";
    X1.Remark = " ";
    X1.State = 6;
    X1.CunDang = UIData.CurrentUser!.Name;
    await ShipUse.Update(X1);
    // widget.added();
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text("航行情况填报"),

        // leading: Icon(Icons.menu),
      ),
      body: ShipUseHuiZhiAddBody(context),
    );
  }

  List<Widget> getWidgetList(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    List<Widget> list2 = <Widget>[];
    List<Widget> list3 = <Widget>[];

    list1.add(InputWidget.inCard(ShipUseAuthority.GetShipTitle(X1)));
    /*
    list1.add(
      InputWidget.inCard( ListTile(
      title: Text("船舶航行工作流程", style: TextStyle(fontWeight: FontWeight.bold),),
    )));*/

    list2.add(InputWidget.getInput("船艇管理人员", c1));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput("管理人员电话", c7));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput("船长、船员", c2));
    list2.add(Divider(
      height: 0.0,
    ));
    list2.add(InputWidget.getInput2("船艇名称及性能情况", c3));

    list1.add(InputWidget.inCard2(list2));

    list3.add(InputWidget.getInput("填报人", c4));
    list3.add(Divider(
      height: 0.0,
    ));
    list3.add(InputWidget.getInput2("当日天气及库面情况", c5));
    list3.add(Divider(
      height: 0.0,
    ));
    list3.add(InputWidget.getInput2("航行过程及停靠确认情况", c6));

    list1.add(InputWidget.inCard2(list3));
    list1.add(
        InputWidget.inCard(InputWidget.getButton("保存", () => upload(context))));
    //list1.add(getCLWidget(s1.State==6, Helper.DateTimeFormat(s1.HZQMTM), s1.HZQM));
    return list1;
  }

  ShipUseHuiZhiAddBody(BuildContext context) => SingleChildScrollView(
        child: ShipUseHuiZhiAddFields(context),
      );

  ShipUseHuiZhiAddFields(BuildContext context) {
    return Container(child: Column(children: getWidgetList(context)));
  }
}
